package org.ielts.util;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.ss.usermodel.Cell;

import com.yifeng.poi.CellReader;

public class SimpleCellReader implements CellReader {
	private boolean numberFirst = true;

	public SimpleCellReader() {

	}

	public SimpleCellReader(boolean numberFirst) {
		this.numberFirst = numberFirst;
	}

	public Object read(HSSFCell cell) {
		Object value = null;
		if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
			value = cell.getStringCellValue();
		} else if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
			if (numberFirst) {
				try {
					value = cell.getNumericCellValue();
				} catch (Exception ex) {
					value = cell.getDateCellValue();
				}
			} else {
				try {
					value = cell.getDateCellValue();
				} catch (Exception ex) {
					value = cell.getNumericCellValue();
				}
			}

		}

		return value;
	}
}
